import Vue from 'vue'
import App from './App.vue'
import router from "@/router";
import vuetify from './plugins/vuetify'
import 'vuetify/dist/vuetify.min.css'
import '@mdi/font/css/materialdesignicons.css'
import axios from "axios";

Vue.config.productionTip = false;
Vue.prototype.$serverUrl = 'http://www.lxaiot.net:8080';
Vue.prototype.$refresh = function () {
    let refreshToken = localStorage.getItem('refreshToken');
    return axios.post(`${this.$serverUrl}/api/auth/token`, {refreshToken})
        .then(response => {
            const token = response.data.token;
            refreshToken = response.data.refreshToken;
            // console.log(`newToken ${token}`);
            // console.log("newRefresh Token" + refreshToken);
            localStorage.setItem('token', token);
            localStorage.setItem('refreshToken', refreshToken);
            return 'success';
        })
        .catch(error => {
            localStorage.clear();
            alert("状态信息过期，请重新登录");
            this.$router.push('/');
            return error;
        })
}

new Vue({
    router,
    vuetify,
    render: h => h(App)
}).$mount('#app')


